home *** CD-ROM | disk | FTP | other *** search
- program TrkTable;
- {$APPTYPE CONSOLE}
- uses
- SysUtils, DB, DBTables;
- var
- f: Text;
- i: Integer;
- Str,Agent: String;
- hits: Integer = 0;
- refer: Integer = 0;
-
- function CopyStripDelete(var Str: String; From,Len: Integer): String;
- begin
- Result := Copy(Str,From,Len); { copy }
- Delete(Str,1,Len); { delete }
- Len := Length(Result);
- while Result[Len] = #32 do Dec(Len);
- SetLength(Result,Len) { strip }
- end {CopyStripDelete};
-
- begin
- if ParamCount = 0 then
- begin
- writeln('Usage: TrkTable [datfile]');
- Halt
- end;
-
- with TTable.Create(nil) do
- try
- Active := False;
- TableType := ttParadox;
- TableName := ParamStr(1)+'.DB';
- with FieldDefs do
- begin
- Clear;
- Add('DateTime', ftString, 24, FALSE);
- Add('Hours', ftInteger, 0, FALSE);
- Add('IP', ftString, 16, FALSE);
- Add('Browser', ftString, 32, FALSE);
- Add('OSystem', ftString, 32, FALSE);
- Add('ThisPage', ftString, 128, FALSE);
- Add('Referrer', ftString, 128, FALSE);
- end;
- CreateTable;
- Open;
- System.Assign(f,ParamStr(1)+'.trk');
- System.Reset(f);
- while not System.Eof(f) do
- begin
- readln(f,Str);
- Append;
- Agent := CopyStripDelete(Str,1,24);
- FieldByName('DateTime').AsString := Agent;
- System.Delete(Agent,1,11);
- if Pos('AM',Agent) > 0 then
- begin
- System.Delete(Agent,Pos(':',Agent),255);
- if Agent = '12' then
- FieldByName('Hours').AsInteger := 0
- else FieldByName('Hours').AsInteger := StrToInt(Agent)
- end
- else { PM }
- begin
- System.Delete(Agent,Pos(':',Agent),255);
- FieldByName('Hours').AsInteger := StrToInt(Agent) + 12
- end;
- FieldByName('IP').AsString :=
- CopyStripDelete(Str,1,16);
- Agent := CopyStripDelete(Str,1,128);
- if (Pos('Windows NT', Agent) > 0) or (Pos('WinNT', Agent) > 0) then { WinNT }
- FieldByName('OSystem').AsString := 'WinNT'
- else
- if (Pos('Windows 95', Agent) > 0) or (Pos('Win95', Agent) > 0) then { Windows 95 }
- FieldByName('OSystem').AsString := 'Win95'
- else
- if (Pos('Windows 98', Agent) > 0) or (Pos('Win98', Agent) > 0) then { Windows 98 }
- FieldByName('OSystem').AsString := 'Win98'
- else
- if Pos('Win16', Agent) > 0 then
- FieldByName('OSystem').AsString := 'Win16'
- else
- if Pos('Linux', Agent) > 0 then
- FieldByName('OSystem').AsString := 'Linux'
- else
- if Pos('Teleport', Agent) > 0 then
- FieldByName('OSystem').AsString := 'Teleport'
- else
- FieldByName('OSystem').AsString := 'other';
- if Pos('(compatible; ',Agent) > 0 then
- begin
- System.Delete(Agent,1,pos('(compatible; ',Agent)+12);
- if Pos('MSIE',Agent) > 0 then
- System.Delete(Agent,1,Pos('MSIE',Agent)-1);
- if Pos(';',Agent) > 0 then
- System.Delete(Agent,Pos(';',Agent),255)
- else
- if Pos(')',Agent) > 0 then
- System.Delete(Agent,Pos(')',Agent),255)
- end
- else
- if Pos('MSIE',Agent) > 0 then
- System.Delete(Agent,1,Pos('MSIE',Agent)-1)
- else
- if Pos(' ',Agent) > 0 then
- System.Delete(Agent,Pos(' ',Agent),255);
- if Pos('Mozilla/',Agent) = 1 then
- begin
- System.Delete(Agent,1,8);
- Agent := 'Netscape ' + Agent
- end
- else
- if (Length(Agent) < 2) or
- (Agent[1] = '(') then Agent := 'other';
- i := Pos(' ',Agent);
- if i > 0 then
- begin
- repeat
- Inc(i)
- until not (Agent[i] in ['0'..'9','.']);
- System.Delete(Agent,i,255);
- i := Pos('.0',Agent);
- if (i > 0) and (Length(Agent) > i+1) then
- begin
- System.Delete(Agent,i+3,255);
- Agent[i+2] := 'x' { 4.0x }
- end
- end;
- if (FieldByName('OSystem').AsString = 'other') and
- (Pos('MSIE',Agent) > 0) then
- FieldByName('OSystem').AsString := 'Win16';
- FieldByName('Browser').AsString := Agent;
- FieldByName('ThisPage').AsString :=
- CopyStripDelete(Str,1,128);
- FieldByName('Referrer').AsString :=
- CopyStripDelete(Str,1,128);
- if FieldByName('Referrer').AsString <> '@' then
- Inc(refer); // actual referrer info
- Post;
- Inc(hits)
- end;
- writeln(hits,' page requests (',
- (refer*100) div hits,'% referred) ',
- 'in logfile ',ParamStr(1))
- finally
- System.Close(f);
- Close;
- Free
- end
- end.
-